package com.easy.sk.config;

import com.easy.common.util.SYS;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SKMQConfig {
    @Bean
    public Queue skQueue()
    {
        Queue skQueue = new Queue(SYS.SK_QUEUE);
        return skQueue;
    }
    // 秒杀失败的队列     死信队列
    @Bean
    public Queue dlxQueue()
    {
        Queue skQueue = new Queue(SYS.SK_DLX_QUEUE);
        return skQueue;
    }
    // 秒杀的交换机
    @Bean
    public DirectExchange skExchange()
    {
        DirectExchange skExchange = new DirectExchange(SYS.SK_EXCHANGE);
        return skExchange;
    }
    @Bean
    public Binding skBinding(@Qualifier("skQueue")Queue skQueue, @Qualifier("skExchange")DirectExchange skExchange) {
        return BindingBuilder.bind(skQueue).to(skExchange).with(SYS.SK_ROUTING_KEY);
    }
    @Bean
    public Binding skDLXBinding(@Qualifier("dlxQueue")Queue dlxQueue, @Qualifier("skExchange")DirectExchange skExchange) {
        return BindingBuilder.bind(dlxQueue).to(skExchange).with(SYS.SK_DLX_ROUTING_KEY);
    }
}
